<template>
  <div class="login-phone">
    <el-form label-width="70px" :rules="rules" :model="userInfo" ref="formRef">
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="userInfo.phone"
          placeholder="请输入手机号"
        ></el-input>
      </el-form-item>
      <div>
        <el-form-item label="验证码" prop="verifyCode">
          <div class="get-code">
            <el-input v-model="userInfo.verifyCode" maxlength="6"></el-input
            ><el-button type="primary">获取验证码</el-button>
          </div>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { rules } from '../config/accountConfig'
import { useStore } from 'vuex'
import type { ElForm } from 'element-plus'
export default defineComponent({
  setup() {
    const store = useStore()
    const userInfo = reactive({
      phone: '',
      verifyCode: ''
    })
    const formRef = ref<InstanceType<typeof ElForm>>()

    const loginAction = () => {
      formRef.value?.validate((valid) => {
        valid && store.dispatch('login/phoneLoginAction', { ...userInfo })
      })
    }

    return { rules, userInfo, formRef, loginAction }
  }
})
</script>

<style lang="scss" scoped>
.get-code {
  display: flex;
  .el-button {
    margin-left: 8px;
  }
}
</style>
